const anchor = require('@coral-xyz/anchor');

const solchain = require('./SoChain');
const config = require('./config');
const main = async ()=> {
    let tx = await solchain.getTransaction(config.txId);
    console.log('tx: ', tx);
    let abi = config.abi;
    const coder = new anchor.BorshCoder(config.abi);
    const eventParser = new anchor.EventParser("9J17hVJXCcMsD1E7Kv5yNKEgQAhwcu4NvtPQvXkgesiV", coder);
    const events = eventParser.parseLogs(tx.meta.logMessages, false);
    console.log('events: ', events);

    let index = 0;
    for(let event of events) {
        console.log('event: ', event);
        let docodeEvent =[];
        let decodeEvent = [];
        decodeEvent.event = event.name;
        decodeEvent.data = event.data;
        decodeEvent.eventIndex = index;
        index ++;
        decodeEvent.args = {};

        let abiJson = abi.events.find(function(json){
            return (json.name === event.name);
        });
        console.log('abiJson: ', abiJson);

    }
}

main();